/**
 */
package de.thwildau.tm.moses.thrift.thrift.impl;

import de.thwildau.tm.moses.thrift.thrift.Annotation;
import de.thwildau.tm.moses.thrift.thrift.ConstValue;
import de.thwildau.tm.moses.thrift.thrift.Field;
import de.thwildau.tm.moses.thrift.thrift.FieldType;
import de.thwildau.tm.moses.thrift.thrift.ThriftPackage;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.MinimalEObjectImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Field</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link de.thwildau.tm.moses.thrift.thrift.impl.FieldImpl#getFieldId <em>Field Id</em>}</li>
 *   <li>{@link de.thwildau.tm.moses.thrift.thrift.impl.FieldImpl#getFieldReq <em>Field Req</em>}</li>
 *   <li>{@link de.thwildau.tm.moses.thrift.thrift.impl.FieldImpl#getType <em>Type</em>}</li>
 *   <li>{@link de.thwildau.tm.moses.thrift.thrift.impl.FieldImpl#getName <em>Name</em>}</li>
 *   <li>{@link de.thwildau.tm.moses.thrift.thrift.impl.FieldImpl#getValue <em>Value</em>}</li>
 *   <li>{@link de.thwildau.tm.moses.thrift.thrift.impl.FieldImpl#getAnnotation <em>Annotation</em>}</li>
 *   <li>{@link de.thwildau.tm.moses.thrift.thrift.impl.FieldImpl#getFields <em>Fields</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class FieldImpl extends MinimalEObjectImpl.Container implements Field
{
  /**
   * The default value of the '{@link #getFieldId() <em>Field Id</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getFieldId()
   * @generated
   * @ordered
   */
  protected static final String FIELD_ID_EDEFAULT = null;

  /**
   * The cached value of the '{@link #getFieldId() <em>Field Id</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getFieldId()
   * @generated
   * @ordered
   */
  protected String fieldId = FIELD_ID_EDEFAULT;

  /**
   * The default value of the '{@link #getFieldReq() <em>Field Req</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getFieldReq()
   * @generated
   * @ordered
   */
  protected static final String FIELD_REQ_EDEFAULT = null;

  /**
   * The cached value of the '{@link #getFieldReq() <em>Field Req</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getFieldReq()
   * @generated
   * @ordered
   */
  protected String fieldReq = FIELD_REQ_EDEFAULT;

  /**
   * The cached value of the '{@link #getType() <em>Type</em>}' containment reference.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getType()
   * @generated
   * @ordered
   */
  protected FieldType type;

  /**
   * The default value of the '{@link #getName() <em>Name</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getName()
   * @generated
   * @ordered
   */
  protected static final String NAME_EDEFAULT = null;

  /**
   * The cached value of the '{@link #getName() <em>Name</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getName()
   * @generated
   * @ordered
   */
  protected String name = NAME_EDEFAULT;

  /**
   * The cached value of the '{@link #getValue() <em>Value</em>}' containment reference.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getValue()
   * @generated
   * @ordered
   */
  protected ConstValue value;

  /**
   * The cached value of the '{@link #getAnnotation() <em>Annotation</em>}' containment reference.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getAnnotation()
   * @generated
   * @ordered
   */
  protected Annotation annotation;

  /**
   * The cached value of the '{@link #getFields() <em>Fields</em>}' containment reference list.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getFields()
   * @generated
   * @ordered
   */
  protected EList<Field> fields;

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  protected FieldImpl()
  {
    super();
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  protected EClass eStaticClass()
  {
    return ThriftPackage.Literals.FIELD;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public String getFieldId()
  {
    return fieldId;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setFieldId(String newFieldId)
  {
    String oldFieldId = fieldId;
    fieldId = newFieldId;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, ThriftPackage.FIELD__FIELD_ID, oldFieldId, fieldId));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public String getFieldReq()
  {
    return fieldReq;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setFieldReq(String newFieldReq)
  {
    String oldFieldReq = fieldReq;
    fieldReq = newFieldReq;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, ThriftPackage.FIELD__FIELD_REQ, oldFieldReq, fieldReq));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public FieldType getType()
  {
    return type;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public NotificationChain basicSetType(FieldType newType, NotificationChain msgs)
  {
    FieldType oldType = type;
    type = newType;
    if (eNotificationRequired())
    {
      ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, ThriftPackage.FIELD__TYPE, oldType, newType);
      if (msgs == null) msgs = notification; else msgs.add(notification);
    }
    return msgs;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setType(FieldType newType)
  {
    if (newType != type)
    {
      NotificationChain msgs = null;
      if (type != null)
        msgs = ((InternalEObject)type).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - ThriftPackage.FIELD__TYPE, null, msgs);
      if (newType != null)
        msgs = ((InternalEObject)newType).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - ThriftPackage.FIELD__TYPE, null, msgs);
      msgs = basicSetType(newType, msgs);
      if (msgs != null) msgs.dispatch();
    }
    else if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, ThriftPackage.FIELD__TYPE, newType, newType));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public String getName()
  {
    return name;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setName(String newName)
  {
    String oldName = name;
    name = newName;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, ThriftPackage.FIELD__NAME, oldName, name));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public ConstValue getValue()
  {
    return value;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public NotificationChain basicSetValue(ConstValue newValue, NotificationChain msgs)
  {
    ConstValue oldValue = value;
    value = newValue;
    if (eNotificationRequired())
    {
      ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, ThriftPackage.FIELD__VALUE, oldValue, newValue);
      if (msgs == null) msgs = notification; else msgs.add(notification);
    }
    return msgs;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setValue(ConstValue newValue)
  {
    if (newValue != value)
    {
      NotificationChain msgs = null;
      if (value != null)
        msgs = ((InternalEObject)value).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - ThriftPackage.FIELD__VALUE, null, msgs);
      if (newValue != null)
        msgs = ((InternalEObject)newValue).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - ThriftPackage.FIELD__VALUE, null, msgs);
      msgs = basicSetValue(newValue, msgs);
      if (msgs != null) msgs.dispatch();
    }
    else if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, ThriftPackage.FIELD__VALUE, newValue, newValue));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public Annotation getAnnotation()
  {
    return annotation;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public NotificationChain basicSetAnnotation(Annotation newAnnotation, NotificationChain msgs)
  {
    Annotation oldAnnotation = annotation;
    annotation = newAnnotation;
    if (eNotificationRequired())
    {
      ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, ThriftPackage.FIELD__ANNOTATION, oldAnnotation, newAnnotation);
      if (msgs == null) msgs = notification; else msgs.add(notification);
    }
    return msgs;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setAnnotation(Annotation newAnnotation)
  {
    if (newAnnotation != annotation)
    {
      NotificationChain msgs = null;
      if (annotation != null)
        msgs = ((InternalEObject)annotation).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - ThriftPackage.FIELD__ANNOTATION, null, msgs);
      if (newAnnotation != null)
        msgs = ((InternalEObject)newAnnotation).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - ThriftPackage.FIELD__ANNOTATION, null, msgs);
      msgs = basicSetAnnotation(newAnnotation, msgs);
      if (msgs != null) msgs.dispatch();
    }
    else if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, ThriftPackage.FIELD__ANNOTATION, newAnnotation, newAnnotation));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public EList<Field> getFields()
  {
    if (fields == null)
    {
      fields = new EObjectContainmentEList<Field>(Field.class, this, ThriftPackage.FIELD__FIELDS);
    }
    return fields;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs)
  {
    switch (featureID)
    {
      case ThriftPackage.FIELD__TYPE:
        return basicSetType(null, msgs);
      case ThriftPackage.FIELD__VALUE:
        return basicSetValue(null, msgs);
      case ThriftPackage.FIELD__ANNOTATION:
        return basicSetAnnotation(null, msgs);
      case ThriftPackage.FIELD__FIELDS:
        return ((InternalEList<?>)getFields()).basicRemove(otherEnd, msgs);
    }
    return super.eInverseRemove(otherEnd, featureID, msgs);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public Object eGet(int featureID, boolean resolve, boolean coreType)
  {
    switch (featureID)
    {
      case ThriftPackage.FIELD__FIELD_ID:
        return getFieldId();
      case ThriftPackage.FIELD__FIELD_REQ:
        return getFieldReq();
      case ThriftPackage.FIELD__TYPE:
        return getType();
      case ThriftPackage.FIELD__NAME:
        return getName();
      case ThriftPackage.FIELD__VALUE:
        return getValue();
      case ThriftPackage.FIELD__ANNOTATION:
        return getAnnotation();
      case ThriftPackage.FIELD__FIELDS:
        return getFields();
    }
    return super.eGet(featureID, resolve, coreType);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @SuppressWarnings("unchecked")
  @Override
  public void eSet(int featureID, Object newValue)
  {
    switch (featureID)
    {
      case ThriftPackage.FIELD__FIELD_ID:
        setFieldId((String)newValue);
        return;
      case ThriftPackage.FIELD__FIELD_REQ:
        setFieldReq((String)newValue);
        return;
      case ThriftPackage.FIELD__TYPE:
        setType((FieldType)newValue);
        return;
      case ThriftPackage.FIELD__NAME:
        setName((String)newValue);
        return;
      case ThriftPackage.FIELD__VALUE:
        setValue((ConstValue)newValue);
        return;
      case ThriftPackage.FIELD__ANNOTATION:
        setAnnotation((Annotation)newValue);
        return;
      case ThriftPackage.FIELD__FIELDS:
        getFields().clear();
        getFields().addAll((Collection<? extends Field>)newValue);
        return;
    }
    super.eSet(featureID, newValue);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public void eUnset(int featureID)
  {
    switch (featureID)
    {
      case ThriftPackage.FIELD__FIELD_ID:
        setFieldId(FIELD_ID_EDEFAULT);
        return;
      case ThriftPackage.FIELD__FIELD_REQ:
        setFieldReq(FIELD_REQ_EDEFAULT);
        return;
      case ThriftPackage.FIELD__TYPE:
        setType((FieldType)null);
        return;
      case ThriftPackage.FIELD__NAME:
        setName(NAME_EDEFAULT);
        return;
      case ThriftPackage.FIELD__VALUE:
        setValue((ConstValue)null);
        return;
      case ThriftPackage.FIELD__ANNOTATION:
        setAnnotation((Annotation)null);
        return;
      case ThriftPackage.FIELD__FIELDS:
        getFields().clear();
        return;
    }
    super.eUnset(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public boolean eIsSet(int featureID)
  {
    switch (featureID)
    {
      case ThriftPackage.FIELD__FIELD_ID:
        return FIELD_ID_EDEFAULT == null ? fieldId != null : !FIELD_ID_EDEFAULT.equals(fieldId);
      case ThriftPackage.FIELD__FIELD_REQ:
        return FIELD_REQ_EDEFAULT == null ? fieldReq != null : !FIELD_REQ_EDEFAULT.equals(fieldReq);
      case ThriftPackage.FIELD__TYPE:
        return type != null;
      case ThriftPackage.FIELD__NAME:
        return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
      case ThriftPackage.FIELD__VALUE:
        return value != null;
      case ThriftPackage.FIELD__ANNOTATION:
        return annotation != null;
      case ThriftPackage.FIELD__FIELDS:
        return fields != null && !fields.isEmpty();
    }
    return super.eIsSet(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public String toString()
  {
    if (eIsProxy()) return super.toString();

    StringBuffer result = new StringBuffer(super.toString());
    result.append(" (fieldId: ");
    result.append(fieldId);
    result.append(", fieldReq: ");
    result.append(fieldReq);
    result.append(", name: ");
    result.append(name);
    result.append(')');
    return result.toString();
  }

} //FieldImpl
